package pair;
//test2
import java.io.*;
import java.util.Arrays;
public class Solution {

	/**
	 * @param args
	 */
	public static void main(String[] args)  throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("data.txt"));
		String line = br.readLine();
		String str[]=line.split(" ");
		int N = Integer.parseInt(str[0]);
		int K = Integer.parseInt(str[1]);
		int a[]=new int[N];
		line = br.readLine();
		str=line.split(" ");
		for(int i=0;i<=N-1;i++){
			a[i]=Integer.parseInt(str[i]);	
		}
		Arrays.sort(a);
		System.out.println(solution1(a,0,N-1,K));
		br.close();
	}

	private static int solution1(int[] a, int i, int j,int k) {
		if(i==j)return 0;
		if(a[j]-a[i]<k)return 0;
		int s=0,mid=(int)Math.floor((i+j)/2);
		s+=solution1(a,i,mid,k);
		s+=solution1(a,mid+1,j,k);
		int ii=mid;
		while(a[mid]-a[ii]<k){
			int jj=mid+1;
			while(a[jj]-a[mid+1]<k&&jj<=j){
				if(a[jj]-a[ii]==k)s++;
				if(++jj>j)break;
			}
			if(--ii<i)break;
		}
		return s;		
	}
}
